/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * SimulacaoMetodosHash.java
 *
 * Created on 12/05/2010, 11:06:16
 */
package Forms;

import E_explicito_ComputedChaining10bits.EncadeamentoCC10bits;
import E_explicito_ComputedChaining2bits.EncadeamentoCC2bits;
import E_explicito_Dinamica.EncadeamentoED;
import E_explicito_EstaticoDCWC.EncadeamentoEE_DCWC;
import E_explicito_EstaticoEICH.EncadeamentoEE_EICH;
import E_explicito_EstaticoEISCH.EncadeamentoEE_EISCH;
import E_explicito_EstaticoLICH.EncadeamentoEE_LICH;
import E_explicito_EstaticoLISCH.EncadeamentoEE_LISCH;
import E_implicito_LinearQuotient.EncadeamentoILQ;
import E_implicito_Sequencial.EncadeamentoIS;
import E_implicito_Brent.EncadeamentoIB;
import E_implicito_Arvore_Binaria.EncadeamentoIAB;
import arquivos.Centraliza;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

/**
 *
 * @author rafaelob
 */
public class SimulacaoMetodosHash extends javax.swing.JFrame {

    ArrayList<Integer> numbers;

    /** Creates new form SimulacaoMetodosHash */
    public SimulacaoMetodosHash() {
        initComponents();
        numbers = new ArrayList<Integer>();
        jLabelAF.setEnabled(false);
        jSpinnerAF.setEnabled(false);
        Centraliza.setCentro(this, 0, 200);
        this.setResizable(false);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jPanel2 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jComboBoxOpcao = new javax.swing.JComboBox();
        jLabelTabelaSize = new javax.swing.JLabel();
        jComboBoxTamanhoTabela = new javax.swing.JComboBox();
        jButtonAdicionar = new javax.swing.JButton();
        jSpinnerNumberInsert = new javax.swing.JSpinner();
        jButtonDropLast = new javax.swing.JButton();
        jButtonReset = new javax.swing.JButton();
        jLabelAF = new javax.swing.JLabel();
        jSpinnerAF = new javax.swing.JSpinner();
        jLabelQuant = new javax.swing.JLabel();
        jLabelQuantidadeInserida = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jButtonVoltar = new javax.swing.JButton();
        jButtonGerar = new javax.swing.JButton();
        jSeparator2 = new javax.swing.JSeparator();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setFont(new java.awt.Font("Dialog", 1, 18));
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("Simulação de Métodos Hash");
        jPanel1.add(jLabel1);

        jSeparator1.setForeground(new java.awt.Color(255, 0, 51));

        jPanel2.setAutoscrolls(true);

        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel2.setText("Selecione um Método ");
        jLabel2.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jPanel2.add(jLabel2);

        jComboBoxOpcao.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Encadeamento E. Dinânimco\t", "Encadeamento E. Estático DCWC", "Encadeamento E. Estático LISCH", "Encadeamento E. Estático EISCH", "Encadeamento E. Estático LICH", "Encadeamento E. Estático EICH", "Encadeamento I. Sequencial", "Encadeamento I. Linear Quotient", "Encadeamento I. Brent", "Encadeamento I. Árvore Binária", "Encadeamento I. C.Computada 10bits", "Encadeamento I. C.Computada 2bits" }));
        jComboBoxOpcao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxOpcaoActionPerformed(evt);
            }
        });
        jPanel2.add(jComboBoxOpcao);

        jLabelTabelaSize.setText("Tamanho da Tabela:");
        jPanel2.add(jLabelTabelaSize);

        jComboBoxTamanhoTabela.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "11", "13", "17", "19", "23", "29" }));
        jPanel2.add(jComboBoxTamanhoTabela);

        jButtonAdicionar.setText("Adicionar");
        jButtonAdicionar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAdicionarActionPerformed(evt);
            }
        });
        jPanel2.add(jButtonAdicionar);

        jSpinnerNumberInsert.setModel(new javax.swing.SpinnerNumberModel(0, 0, 50000, 1));
        jSpinnerNumberInsert.setMinimumSize(new java.awt.Dimension(104, 20));
        jSpinnerNumberInsert.setPreferredSize(new java.awt.Dimension(104, 20));
        jPanel2.add(jSpinnerNumberInsert);

        jButtonDropLast.setText("Drop Last");
        jButtonDropLast.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonDropLastActionPerformed(evt);
            }
        });
        jPanel2.add(jButtonDropLast);

        jButtonReset.setText("Resetar");
        jButtonReset.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonResetActionPerformed(evt);
            }
        });
        jPanel2.add(jButtonReset);

        jLabelAF.setText("Address Factor :");
        jPanel2.add(jLabelAF);

        jSpinnerAF.setModel(new javax.swing.SpinnerNumberModel(0.05d, 0.05d, 0.9d, 0.01d));
        jSpinnerAF.setPreferredSize(new java.awt.Dimension(64, 20));
        jPanel2.add(jSpinnerAF);

        jLabelQuant.setText("Quantidade de Números a serem Inseridos:");
        jPanel2.add(jLabelQuant);

        jLabelQuantidadeInserida.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jPanel2.add(jLabelQuantidadeInserida);

        jPanel3.setLayout(new java.awt.GridBagLayout());

        jButtonVoltar.setText("Voltar");
        jButtonVoltar.setPreferredSize(new java.awt.Dimension(90, 25));
        jButtonVoltar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonVoltarActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 20);
        jPanel3.add(jButtonVoltar, gridBagConstraints);

        jButtonGerar.setText("Gerar");
        jButtonGerar.setPreferredSize(new java.awt.Dimension(90, 25));
        jButtonGerar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonGerarActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 20);
        jPanel3.add(jButtonGerar, gridBagConstraints);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 602, Short.MAX_VALUE)
            .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 602, Short.MAX_VALUE)
            .addComponent(jSeparator2, javax.swing.GroupLayout.DEFAULT_SIZE, 602, Short.MAX_VALUE)
            .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 602, Short.MAX_VALUE)
            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, 602, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 1, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, 88, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonAdicionarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAdicionarActionPerformed
        String tamTabela = jComboBoxTamanhoTabela.getSelectedItem().toString();
        int tamanhoTabela = Integer.parseInt(tamTabela);
        if (tamanhoTabela <= numbers.size()) {
            Alert alert = new Alert();
            alert.setMessage("Quantidade Máxima de Números Atingida");
            alert.setVisible(true);
        } else {
            if (numbers.contains((Integer) jSpinnerNumberInsert.getValue())) {
                Alert alert = new Alert();
                alert.setMessage("Número já inserido, insira outro");
                alert.setVisible(true);
            } else {
                numbers.add((Integer) jSpinnerNumberInsert.getValue());
                jLabelQuantidadeInserida.setText(String.valueOf(numbers.size()));

            }
        }
    }//GEN-LAST:event_jButtonAdicionarActionPerformed

    private void jButtonDropLastActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonDropLastActionPerformed
        if (numbers.size() == 0) {
            Alert alert = new Alert();
            alert.setMessage("Não existem números para serem retirados");
            alert.setVisible(true);
        } else {
            numbers.remove(numbers.size() - 1);
            jLabelQuantidadeInserida.setText(String.valueOf(numbers.size()));

        }
    }//GEN-LAST:event_jButtonDropLastActionPerformed

    private void jButtonResetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonResetActionPerformed
        Alert alert = new Alert();
        alert.setMessage("Deseja Resetar? Clique em OK");
        alert.setVisible(true);
        alert.getjButton1().addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                numbers = new ArrayList<Integer>();
                jLabelQuantidadeInserida.setText(String.valueOf(numbers.size()));
            }
        });



    }//GEN-LAST:event_jButtonResetActionPerformed

    private void jButtonVoltarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonVoltarActionPerformed
        /*      this.dispose();
        CompareMetodosHash metoDosHash = new CompareMetodosHash();
        metoDosHash.setVisible(true); */
}//GEN-LAST:event_jButtonVoltarActionPerformed

    private void jButtonGerarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonGerarActionPerformed
        String tamTabela = jComboBoxTamanhoTabela.getSelectedItem().toString();
        int tamanhoTabela = Integer.parseInt(tamTabela);

        if (tamanhoTabela < numbers.size()) {
            Alert alert = new Alert();
            alert.setMessage("Quantidade de Números Maior que Tamanho da Tabela");
            alert.setVisible(true);
        } else {
            switch (jComboBoxOpcao.getSelectedIndex()) {
                case 0:
                    EncadeamentoED encadeamentoED = new EncadeamentoED(tamanhoTabela, numbers);
                    ResultadoSimulacao resultadoED = new ResultadoSimulacao();
                    resultadoED.setResultado(tamanhoTabela, encadeamentoED,numbers.size());
                    resultadoED.setVisible(true);
                    this.dispose();
                    break;
                case 1:
                    EncadeamentoEE_DCWC encadeamentoEE_DCWC = new EncadeamentoEE_DCWC(tamanhoTabela, numbers);
                    ResultadoSimulacao resultadoEE_DCWC = new ResultadoSimulacao();
                    resultadoEE_DCWC.setResultado(tamanhoTabela, encadeamentoEE_DCWC,numbers.size());
                    resultadoEE_DCWC.setVisible(true);
                    this.dispose();

                    break;
                case 2:
                    EncadeamentoEE_LISCH encadeamentoEE_LISCH = new EncadeamentoEE_LISCH(tamanhoTabela, numbers);
                    ResultadoSimulacao resultadoEE_LISCH = new ResultadoSimulacao();
                    resultadoEE_LISCH.setResultado(tamanhoTabela, encadeamentoEE_LISCH,numbers.size());
                    resultadoEE_LISCH.setVisible(true);
                    resultadoEE_LISCH.setVisible(true);
                    this.dispose();

                    break;


                case 3:
                    EncadeamentoEE_EISCH encadeamentoEE_EISCH = new EncadeamentoEE_EISCH(tamanhoTabela, numbers);
                    ResultadoSimulacao resultadoEE_EISCH = new ResultadoSimulacao();
                    resultadoEE_EISCH.setResultado(tamanhoTabela, encadeamentoEE_EISCH,numbers.size());
                    resultadoEE_EISCH.setVisible(true);
                    resultadoEE_EISCH.setVisible(true);
                    this.dispose();

                    break;
                case 4:

                    EncadeamentoEE_LICH encadeamentoEE_LICH = new EncadeamentoEE_LICH(tamanhoTabela, Double.parseDouble(jSpinnerAF.getValue().toString()), numbers);
                    ResultadoSimulacao resultadoEE_LICH = new ResultadoSimulacao();
                    resultadoEE_LICH.setResultado(tamanhoTabela, encadeamentoEE_LICH,numbers.size());
                    resultadoEE_LICH.setVisible(true);;
                    this.dispose();
                    break;
                case 5:
                    EncadeamentoEE_EICH encadeamentoEE_EICH = new EncadeamentoEE_EICH(tamanhoTabela, Double.parseDouble(jSpinnerAF.getValue().toString()), numbers);
                    ResultadoSimulacao resultadoEE_EICH = new ResultadoSimulacao();
                    resultadoEE_EICH.setResultado(tamanhoTabela, encadeamentoEE_EICH,numbers.size());
                    resultadoEE_EICH.setVisible(true);
                    this.dispose();
                    break;

                case 6:
                    EncadeamentoIS encadeamentoIS = new EncadeamentoIS(tamanhoTabela, numbers);
                    ResultadoSimulacao resultadoIS = new ResultadoSimulacao();
                    resultadoIS.setResultado(tamanhoTabela, encadeamentoIS, numbers.size());
                    resultadoIS.setVisible(true);
                    this.dispose();
                    break;
                case 7:
                    EncadeamentoILQ encadeamentoILQ = new EncadeamentoILQ(tamanhoTabela, numbers);
                    ResultadoSimulacao resultadoILQ = new ResultadoSimulacao();
                    resultadoILQ.setResultado(tamanhoTabela, encadeamentoILQ, numbers.size());
                    resultadoILQ.setVisible(true);
                    this.dispose();
                    break;
                case 8:
                    EncadeamentoIB encadeamentoIB = new EncadeamentoIB(tamanhoTabela, numbers);
                    ResultadoSimulacao resultadoIB = new ResultadoSimulacao();
                    resultadoIB.setResultado(tamanhoTabela, encadeamentoIB, numbers.size());
                    resultadoIB.setVisible(true);
                    this.dispose();
                    break;
                case 9:
                    EncadeamentoIAB encadeamentoIAB = new EncadeamentoIAB(tamanhoTabela, numbers);
                    ResultadoSimulacao resultadoIAB = new ResultadoSimulacao();
                    resultadoIAB.setResultado(tamanhoTabela, encadeamentoIAB, numbers.size());
                    resultadoIAB.setVisible(true);
                    this.dispose();
                    break;

                case 10:
                    EncadeamentoCC10bits encadeamentoCC10bits = new EncadeamentoCC10bits(tamanhoTabela, numbers);
                    ResultadoSimulacao resultadoCC10bits = new ResultadoSimulacao();
                    resultadoCC10bits.setResultado(tamanhoTabela, encadeamentoCC10bits, numbers.size());
                    resultadoCC10bits.setVisible(true);
                    this.dispose();
                    break;
                default:
                    break;
                    case 11:
                    EncadeamentoCC2bits encadeamentoCC2bits = new EncadeamentoCC2bits(tamanhoTabela, numbers);
                    ResultadoSimulacao resultadoCC2bits = new ResultadoSimulacao();
                    resultadoCC2bits.setResultado(tamanhoTabela, encadeamentoCC2bits, numbers.size());
                    resultadoCC2bits.setVisible(true);
                    this.dispose();
                    break;

            }





        }
    }//GEN-LAST:event_jButtonGerarActionPerformed

    private void jComboBoxOpcaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxOpcaoActionPerformed
        if ((jComboBoxOpcao.getSelectedIndex() == 4) || (jComboBoxOpcao.getSelectedIndex() == 5)) {
            jLabelAF.setEnabled(true);
            jSpinnerAF.setEnabled(true);
        } else {
            jLabelAF.setEnabled(false);
            jSpinnerAF.setEnabled(false);
        }
    }//GEN-LAST:event_jComboBoxOpcaoActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new SimulacaoMetodosHash().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonAdicionar;
    private javax.swing.JButton jButtonDropLast;
    private javax.swing.JButton jButtonGerar;
    private javax.swing.JButton jButtonReset;
    private javax.swing.JButton jButtonVoltar;
    private javax.swing.JComboBox jComboBoxOpcao;
    private javax.swing.JComboBox jComboBoxTamanhoTabela;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabelAF;
    private javax.swing.JLabel jLabelQuant;
    private javax.swing.JLabel jLabelQuantidadeInserida;
    private javax.swing.JLabel jLabelTabelaSize;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSpinner jSpinnerAF;
    private javax.swing.JSpinner jSpinnerNumberInsert;
    // End of variables declaration//GEN-END:variables
}
